/*** Class Name: ifulfillTaskHistoryBatch 
* Author: Accenture      
* Requirement/Project Name: iFULFILL
* Requirement/Project Description:SFDC should verify that the CSS system is not down prior to sending an TaskHistory outbound message.
* This batch will process all the Failed taskHistory records where status code not equal to '0' .
* 
* **/
global class ifulfillTaskHistoryBatch implements Schedulable{

    global void execute(SchedulableContext sc) {
        ifulfillTaskHistoryRestAPIBatch  taskHistory= new ifulfillTaskHistoryRestAPIBatch(); 
        taskHistory.query='select Id,AutoNotes__c,Status_Code__c,Delivery_Status__c,Error_Stack__c,Error_Message__c,CreatedByID,Fullfilment_Item__c,LastModifiedDate from Fulfillment_Step_History__c where (Status_Code__c != null or Status_Code__c !=\'\') and Status_Code__c!=\'0\' limit 400' ;
        ID batchprocessid = Database.executeBatch(taskHistory,1);
      
    }  
    
    /* test class for classes/triggers */
 
  static testMethod void testifulfillTaskHistoryRESTAPIBatch () 
  {
     
        test.starttest();
        Fullfilment_Item__c fi = new Fullfilment_Item__c(   Main_Listing_Phone_Number__c = '100',Listed_Name__c ='XYZ',Heading_Name__c ='Heading name',Item_Id__c = 'Item id' ,Product_Code__c ='p1',UDAC__c ='Udac1',Region__c = 'region1',Transaction_Type__c ='New');
        insert fi;
        Fulfillment_Step_History__c  s = new Fulfillment_Step_History__c ( Status_Code__c='1', Fullfilment_Item__c=fi.id, Error_Stack__c= 'Unable to contact CSS.PleaFailed', Error_Message__c= 'Unable to contac');
        insert s;
     
        ifulfillTaskHistoryRestAPIBatch  taskHistory= new ifulfillTaskHistoryRestAPIBatch(); 
        taskHistory.query='select Id,AutoNotes__c,Status_Code__c,Delivery_Status__c,Error_Stack__c,Error_Message__c,CreatedByID,Fullfilment_Item__c,LastModifiedDate from Fulfillment_Step_History__c where (Status_Code__c != null or Status_Code__c !=\'\') and Status_Code__c!=\'0\' limit 400' ;
        ID batchprocessid = Database.executeBatch(taskHistory,1);
        
        ifulfillTaskHistoryBatch trackHist = new ifulfillTaskHistoryBatch ();
        String sch = '0 0 23 * * ?';
        system.schedule('Ifulfill', sch , trackHist );
        test.stopTest();
  }           


}